package erfgame.core.world;

import java.util.List;


import erfgame.core.world.generator.WorldGeneratorUtils;
import erfgame.core.world.terrain.BlockSurfaceImageFactory;

public class WorldUpdateHelper {
	private WorldUpdater worldUpdater;
	private WorldDAOManager worldDAOManager;
	private BlockSurfaceImageFactory surfaceImageFactory;
	
	public WorldUpdateHelper( WorldUpdater worldUpdater, WorldDAOManager worldDAOManager, BlockSurfaceImageFactory surfaceImageFactory ) {
		this.worldUpdater = worldUpdater;
		this.worldDAOManager = worldDAOManager;
		this.surfaceImageFactory = surfaceImageFactory;
	}
	
	public void updateWorld( World world, long ticks ) {
		
		List<WorldUpdateDescription> updates;
		updates = worldUpdater.update(world, ticks);
		// TODO normalise so there are no overlaps
		for( int i = updates.size(); i>0; ) {
			i--;
			WorldUpdateDescription update;
			update = updates.get( i );
			WorldGeneratorUtils.update(world, update, surfaceImageFactory, worldDAOManager);
		}
	}
}
